<?php

class Front_web extends arfaController{
	
	public function __construct()
	{
		parent::__construct();
		$this->load->model("m_ps_pemohon");
		$this->load->model("m_ijin_model");
	}
	
	public function index()
	{
		$data["content"] = $this->load->view("v_front_web","",true);
		$this->load->view('main2',$data);
	}
	
	public function front_input_ps()
	{
		$this->form_validation->set_rules("nama","Nama","required");
		$this->form_validation->set_rules("no_telp","No. Telepon","required");
		$this->form_validation->set_rules("isi","Isi","required");
		
		if($this->form_validation->run() == FALSE)
		{
			$data["post_action"]	= "front_web/front_input_ps";
			$data["dropdown_ijin"] 			= $this->m_ijin_model->get();
			$data["content"]		= $this->load->view("form_input_ps_front",$data,true);
			$this->load->view('main2',$data);
		}
		else
		{
			$get_nama		= $this->input->post("nama");
			$get_notelp		= $this->input->post("no_telp");
			$get_email		= $this->input->post("email");
			$get_isi		= $this->input->post("isi");
			$get_media		= $this->input->post("media");
			$get_ijin		= $this->input->post("ijin");
			$get_uptsa		= $this->input->post("no_uptsa");
			$get_tanggal	= date('Y-m-d');
			$get_j_ijin		= $this->input->post("terkait_ijin");
			
			if($get_j_ijin == 1)
			{
				$data = array(
					"NAMA"		=> $get_nama,
					"NO_TELPON"	=> $get_notelp,
					"EMAIL"		=> $get_email,
					"ISI"		=> $get_isi,
					"MEDIA"		=> $get_media,
					"KD_IJIN"	=> $get_ijin,
					"NO_UPTSA"	=> $get_uptsa,
					"TANGGAL"	=> $get_tanggal
				);
				
				$this->m_ps_pemohon->save($data);
				echo "<script>alert('Data berhasil disimpan. Terimakasih atas partisipasi anda.');</script>";
				echo "<script>document.location='';</script>";
			}
			elseif($get_j_ijin == 2)
			{
				$data = array(
					"NAMA"		=> $get_nama,
					"NO_TELPON"	=> $get_notelp,
					"EMAIL"		=> $get_email,
					"ISI"		=> $get_isi,
					"MEDIA"		=> $get_media,
					"KD_IJIN"	=> NULL,
					"NO_UPTSA"	=> NULL,
					"TANGGAL"	=> $get_tanggal
				);
				
				$this->m_ps_pemohon->save($data);
				echo "<script>alert('Data berhasil disimpan. Terimakasih atas partisipasi anda.');</script>";
				echo "<script>document.location='';</script>";
			}
		}
	}
}